package com.ruoyi.deeplearn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deeplearn.domain.DeepAlgorithm;
import com.ruoyi.deeplearn.service.IDeepAlgorithmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 算法Controller
 *
 * @author 任伟伟
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/deeplearn/algorithm")
public class DeepAlgorithmController extends BaseController
{
    @Autowired
    private IDeepAlgorithmService deepAlgorithmService;

    /**
     * 查询算法列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:algorithm:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeepAlgorithm deepAlgorithm)
    {
        startPage();
        List<DeepAlgorithm> list = deepAlgorithmService.selectDeepAlgorithmList(deepAlgorithm);
        return getDataTable(list);
    }
//    @PreAuthorize("@ss.hasPermi('deeplearn:algorithm:list')")
    @GetMapping("/list/all")
    public AjaxResult listAll(DeepAlgorithm deepAlgorithm)
    {
        List<DeepAlgorithm> list = deepAlgorithmService.selectDeepAlgorithmList(deepAlgorithm);
        return AjaxResult.success(list);
    }

    /**
     * 导出算法列表
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:algorithm:export')")
    @Log(title = "算法", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeepAlgorithm deepAlgorithm)
    {
        List<DeepAlgorithm> list = deepAlgorithmService.selectDeepAlgorithmList(deepAlgorithm);
        ExcelUtil<DeepAlgorithm> util = new ExcelUtil<DeepAlgorithm>(DeepAlgorithm.class);
        util.exportExcel(response, list, "算法数据");
    }

    /**
     * 获取算法详细信息
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:algorithm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deepAlgorithmService.selectDeepAlgorithmById(id));
    }

    /**
     * 新增算法
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:algorithm:add')")
    @Log(title = "算法", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeepAlgorithm deepAlgorithm)
    {
        return toAjax(deepAlgorithmService.insertDeepAlgorithm(deepAlgorithm));
    }

    /**
     * 修改算法
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:algorithm:edit')")
    @Log(title = "算法", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeepAlgorithm deepAlgorithm)
    {
        return toAjax(deepAlgorithmService.updateDeepAlgorithm(deepAlgorithm));
    }

    /**
     * 删除算法
     */
//    @PreAuthorize("@ss.hasPermi('deeplearn:algorithm:remove')")
    @Log(title = "算法", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deepAlgorithmService.deleteDeepAlgorithmByIds(ids));
    }
}
